package cn.iocoder.yudao.module.promotion.coupon.api;


import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.api.promotion.coupon.CouponRecordApi;
import cn.iocoder.yudao.module.api.promotion.coupon.dto.CouponRespDTO;
import cn.iocoder.yudao.module.api.promotion.coupon.dto.CouponUseReqDTO;
import cn.iocoder.yudao.module.promotion.coupon.service.CouponRecordService;
import jakarta.annotation.Nullable;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 优惠劵领取记录 API 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class CouponRecordApiImpl implements CouponRecordApi {

    @Resource
    private CouponRecordService couponRecordService;

    @Override
    public int getCouponCountByUserId(Long userId, @Nullable Integer status) {
        return couponRecordService.getCouponCount(userId, status);
    }

    @Override
    public List<CouponRespDTO> getCouponListByUserId(Long userId, @Nullable Integer status) {
        return BeanUtils.toBean(couponRecordService.getCouponList(userId, status), CouponRespDTO.class);
    }

    @Override
    public List<CouponRespDTO> getUnusedCouponListByUserId(Long userId, List<Integer> scopes) {
        return BeanUtils.toBean(couponRecordService.getUnusedCouponList(userId, scopes), CouponRespDTO.class);
    }

    @Override
    public void useCoupon(CouponUseReqDTO useReqDTO) {
        couponRecordService.useCoupon(useReqDTO.getId(), useReqDTO.getUserId(),
                useReqDTO.getOrderId());
    }

    @Override
    public void returnUsedCoupon(Long id) {
        couponRecordService.returnUsedCoupon(id);
    }

    @Override
    public List<Long> takeCouponsByAdmin(Map<Long, Integer> giveCoupons, Long userId) {
        return couponRecordService.takeCouponsByAdmin(giveCoupons, userId);
    }

    @Override
    public void invalidateCouponsByAdmin(List<Long> giveCouponIds, Long userId) {
        couponRecordService.invalidateCouponsByAdmin(giveCouponIds, userId);
    }

    @Override
    public Map<Long, Boolean> getCouponReceivedStateMap(Long userId, Set<Long> templateIds) {
        return couponRecordService.getCouponReceivedStateMap(userId, templateIds);
    }

}
